require.config({
    baseUrl:"js",
    paths:{
        jquery:"lib/jquery-2.1.4.min",        
        bootstrap:"../assets/bootstrap/js/bootstrap",
        datetimepicker:"../assets/datetimepicker/js/bootstrap-datetimepicker",
        datetimepickerLn:"../assets/datetimepicker/js/locales/bootstrap-datetimepicker.zh-CN",
        checkLogin:"common/checkLogin",
        cookie:"lib/jquery.cookie",
        text:"lib/text",
        artTemplate:"lib/template-web",
        common:"common/common",
        layer:"../assets/layui/lay/modules/layer",
        moment:"lib/moment",
        mui:"lib/mui.min",
        muipicker:"lib/mui.picker.min",
        print:"lib/jQuery.print"
    },
    shim:{
        muipicker:{
            deps:["mui"]
        },
        bootstrap:{
            deps:["jquery"],
            exports : 'bootstrap'
        },
        datetimepicker:{
            deps:["jquery","bootstrap"],
            exports : 'datetimepicker'
        },
        datetimepickerLn:{
            deps:["datetimepicker"],
        },
        layer:{
            deps:["jquery"]
        },
        print:{
            deps:["jquery"]
        }
    }
});

require(["jquery","artTemplate","mui","common","recover","washing","muipicker","bootstrap","datetimepicker","datetimepickerLn","layer","moment","cookie"],
         function($,art,mui,common,recover,washing){
	
        $("#recoverWraper").on("click", function () {            
            recover()
        })
		$("#washingWraper").on("click", function () {            
            washing()
        })
		$("#recoverWraper").trigger("click");
        /*$("#checkboxAll").change(function () {
            $("input[id^=check]").prop("checked", $(this).prop("checked"))
        })
        $("input:checkbox").change(function () {
            console.log( $(this).prop("checked"))
        })*/

	// 点击模块变化选中样式
	$("body").on("click.addborder","span.page_menue_a",function(){
		$("span.page_menue_a").removeClass("active");
		$(this).addClass("active");
	})
	
	// 全选框改变状态
	$("body").on("change.selectall","#checkboxAll",function(){
		$("input[id^=check]").prop("checked", $(this).prop("checked"))
	})
	/** 初始化日期控件 **/
	window.init_datetimepicker_ymd = function (){
        $(".form_datetime").datetimepicker({
        format: 'yyyy-mm-dd',
        language:  'zh-CN',
        weekStart: 1,
        bootcssVer:3,
        todayBtn:  1,
        autoclose: 1,
        todayHighlight: true,
        startView: 2,
        minView: 2,
        pickerPosition: 'bottom-right',
        forceParse: 0,
        keyboardNavigation:1,
        forceParse:1
        });
        $(".datetime_now").val(timenow());
        $(".month_fristday").val(common.monthfirstday());
        $(".datetime_month").val(common.monthnow());
    };
    init_datetimepicker_ymd();

	window.init_datetimepicker_ymdsms = function (){
        $(".form_datetime2").datetimepicker({
        format: 'yyyy-mm-dd hh:ii:ss',
        language:  'zh-CN',
        weekStart: 1,
        bootcssVer:3,
        todayBtn:  1,
        autoclose: 1,
        todayHighlight: true,
        startView: 2,
        minView: 0,
        pickerPosition: 'bottom-right',
        keyboardNavigation:1,
        forceParse:true
        });
        $(".datetime_now").val(timenow());
        
        $(".datetime_month").val(common.monthnow());
    };
    init_datetimepicker_ymdsms();
 
    //设置日期默认当天
      function timenow() {
	    var timenow = new Date();
	    var y = timenow.getFullYear();//年
	    var m = timenow.getMonth() + 1;//月
	    m = m < 10 ? '0' + m : m;
	    var d = timenow.getDate();//日
	    d = d < 10 ? ('0' + d) : d;
	    var time = y + '-' + m + '-' + d;//字符串拼接成自己想要的时间格式，现在是yyyy/mm/dd格式
	    return time;
	}	
    var basePgDate = timenow();
    
    window.setdate_now = function (){
    	var timenow = new Date();
	    var y = timenow.getFullYear();//年
	    var m = timenow.getMonth() + 1;//月
	    m = m < 10 ? '0' + m : m;
	    var d = timenow.getDate();//日
	    d = d < 10 ? ('0' + d) : d;
	    var time = y + '-' + m + '-' + d;//字符串拼接成自己想要的时间格式，现在是yyyy/mm/dd格式
	    return time;
    }
    //设置日期默认当月第一天
    
    
    window.closeLayer =  function (){
        $(".layui-layer-ico.layui-layer-close.layui-layer-close1").trigger("click");
    };
    
   //保存操作人列表
/*   $.get(common.kcUrl() + "base/operatorList.shtml",function(res){
	   var result = eval('(' + res.result + ')');
	   $("#select_operator_list").empty();
	   for(var i=0;i<result.length;i++){
			$("#select_operator_list").append("<option value='"+result[i].user_id+"'>"+result[i].user_name+"</option>"); 
		}	   
   });*/
   
   
   
    //判断容器是否出现滚动条，设置顶部标题行右侧的padding
    window.setPaddingR = function(tag1,tag2,height){
    	if(!$(tag1)[0]){
    		return
    	}
        if($(tag1)[0].scrollHeight>$(tag1)[0].clientHeight||$(tag1)[0].offsetHeight>$(tag1)[0].clientHeight){ 
			$(tag2).css("padding-right","17px");
		}else{
			$(tag2).css("padding-right","0");
		}
        if( $("body").scrollTop()>0 ){
            $("div.main_container").css({
            	"min-height":"100%"
            });
          }else{
        	  $("div.main_container").css({
              	"height":"100%"
          })
          }
    };
    window.setMainHeight = function(){
    	if( $("body")[0].scrollHeight>$("body")[0].clientHeight||$("body")[0].offsetHeight>$("body")[0].clientHeight ){
            $("#mainpage").css({
            	"height":"",
            	"min-height":"100%"
            });
            $("div.main_container,#Vueapp,.slider_bar").css({
            	"height":"auto"
            });
            $("div#manage_main").css({
            	"height":"auto",
            	"min-height": "calc(100% - 44px)"
            });
          }
    };
    setMainHeight();
    window.cancelPaddingR = function(tag1,tag2,height){
        var ulContainerHeight = $(tag1).height();
        if(ulContainerHeight < height){
            $(tag2).css("padding-right","0");
        }
    };
    //验证新增厂家和经销商是否输入必输字段,提示输入
	window.warnMsg = function (text,msg,iptname){
		if(!text){
    		$("#cj_xzcj_ul_svc").find("input[name="+ iptname +"]").addClass("warn_border");
    		layer.msg(msg);
    		setTimeout(function() {
    			$("#cj_xzcj_ul_svc").find("input[name="+ iptname +"]").removeClass("warn_border");  
    	    }, 3000);    		
    	}		
	};
	
    //验证新增出库和入库是否输入必输字段,提示输入
	window.warnMsg2 = function (text,msg,iptname){
		if(!text){
    		$("#rkgl_rklb_ul_svb").find("input[name="+ iptname +"]").addClass("warn_border");
    		layer.msg(msg);
    		setTimeout(function() {
    			$("#rkgl_rklb_ul_svb").find("input[name="+ iptname +"]").removeClass("warn_border");  
    	    }, 3000);    		
    	}		
	};
	
    //验证是否输入必输字段,提示输入
	window.warnMsg3 = function (tag1,tag2,msg){
		tag1.find(tag2).addClass("warn_border");
		layer.msg(msg);
		setTimeout(function() {
			tag1.find(tag2).removeClass("warn_border");  
	    }, 3000);    		
	};
    //验证基本信息选择下拉选项,提示输入
	window.noteSel = function (tagid,msg){		
    		$(tagid).addClass("warn_border");
    		layer.msg(msg);
    		setTimeout(function() {
    			$(tagid).removeClass("warn_border");  
    	    }, 3000);   		
    			
	};
	
	window.toRukuPage = function(){
		$("#kc_rukugl_a").trigger("click");
	};
	window.toChukuPage = function(){
		$("#kc_chukugl_a").trigger("click");
	};
	window.toKucuncxPage = function(){
		$("#kc_kucuncx_a").trigger("click");
	};
	window.toKucunpdPage = function(){
		$("#kc_kucunpd_a").trigger("click");
	};
	window.toJibenxxPage = function(){
		$("#kc_jibenxx_a").trigger("click");
	};
	window.toJingxsPage = function(){
		$("#kc_jingxiaos_a").trigger("click");
	};
	window.toChangjiaPage = function(){
		$("#kc_changjia_a").trigger("click");
	};
	
	
    $('body').on("click",".sub_menu_content",function(event){
        event.stopPropagation();
        $(this).siblings(".sub_menu_content").removeClass("active");
        $(this).addClass("active");
    });

    //入库管理模块
    $("#kc_rukugl_a").on("click",function(){
    	$("div.datetimepicker").remove();
    	var navMenu = '<li style="padding:0 6px;">首页</li>'+
		'<li style="padding:0 6px;" class="active">入库管理</li>';
    	/*var navMenu = '<div class="flow-item flow-item-0"><div>首页</div></div> <div class="flow-item flow-item-2"><div>入库管理</div></div>	';*/
		$("#nav-top").empty().append(navMenu);
        rkgllist(); 
        setMainHeight();
        
    });
    
    //出库管理模块
    $("#kc_chukugl_a").on("click",function(){
    	$("div.datetimepicker").remove();
    	var navMenu = '<li>首页</li>'+
		'<li class="active">出库管理</li>';
		$("#nav-top").empty().append(navMenu);
        chukulist();
        setMainHeight();
        
    });
    
    //库存查询模块
    $("#kc_kucuncx_a").on("click",function(){
    	$("div.datetimepicker").remove();
    	var navMenu = '<li>首页</li>'+
		'<li class="active">库存查询</li>';
		$("#nav-top").empty().append(navMenu);
        kucuncxlist();
        setMainHeight();
    });
    
    //库存盘点模块
    $("#kc_kucunpd_a").on("click",function(){
    	$("div.datetimepicker").remove();
    	var navMenu = '<li>首页</li>'+
		'<li class="active">库存盘点</li>';
		$("#nav-top").empty().append(navMenu);
        kcpdlist();
        setMainHeight();
    });
    
    //基本信息模块
    $("#kc_jibenxx_a").on("click",function(){
    	var navMenu = '<li>首页</li>'+
		'<li class="active">基本信息</li>';
		$("#nav-top").empty().append(navMenu);
        jibenxxlist();
        setMainHeight();
    });
    
    //经销商模块
    $("#kc_jingxiaos_a").on("click",function(){
    	var navMenu = '<li>首页</li>'+
		'<li class="active">经销商</li>';
		$("#nav-top").empty().append(navMenu);
        jxslist();
        setMainHeight();
    });
    
    //厂家模块
    $("#kc_changjia_a").on("click",function(){
    	var navMenu = '<li>首页</li>'+
		'<li class="active">厂家</li>';
    	//var navMenu = "<div id=\"nav-top\" style=\"margin:0;\">\n        \t<div class=\"flow-item flow-item-0\">\n\t\t        <div>\u9996\u9875</div>\n\t\t    </div>\n\t\t    <div class=\"flow-item flow-item-2\">\n\t\t        <div>\u5165\u5E93\u7BA1\u7406</div>\n\t\t    </div>\n\t\t    <div class=\"flow-item flow-item-3\">\n\t\t        <div>\u5165\u5E93\u8BB0\u5F55</div>\n\t\t    </div>\n        </div>";
		$("#nav-top").empty().append(navMenu);
        changjialist();
        setMainHeight();
    });  
    $("#kc_rukugl_a").trigger("click");
    
    $("#login_out").on("click",function(){
    	$.removeCookie('JSESSIONID'); 
    	$.removeCookie('loginName'); 
    	$.removeCookie('loginPwd'); 
    	//跳转到登录页
        location.href="exit.shtml";
    });
});